package com.bitcola.exchange.biz;

import com.bitcola.exchange.entity.MarketUser;
import com.bitcola.exchange.entity.MarketUserKeyMap;
import com.bitcola.exchange.mapper.MarketUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class MarketUserBiz {
    @Autowired
    MarketUserMapper marketUserMapper;

    static  volatile List<MarketUser>marketUserKeyMaps=new ArrayList<>();


    @Scheduled(cron = "0 0/1 * * * ?")
    public void  reloadMarketUsers()
    {
        marketUserKeyMaps=marketUserMapper.selectAll();
    }

    public  MarketUser  getCoinMarketUser(String coinCode)
    {

        var list=marketUserKeyMaps.stream().filter(x->x.getCoinCode().equals(coinCode)).collect(Collectors.toList());
        if(list.size()>0) return list.get(0);
        return  null;
    }

    public  MarketUser  getApiKeyMarketUser(String apiKey)
    {

        var list=marketUserKeyMaps.stream().filter(x->x.getApiKey().equals(apiKey)).collect(Collectors.toList());
        if(list.size()>0) return list.get(0);
        return  null;
    }


    public  MarketUser  getUserIdMarketUser(String userId)
    {

        var list=marketUserKeyMaps.stream().filter(x->x.getUserId().equals(userId)).collect(Collectors.toList());
        if(list.size()>0) return list.get(0);
        return  null;
    }









}
